import pygame, math, sys, os
from Block import Block
from Creature import Creature
from Arrow import Arrow
from Player import Player
from Button import Button
pygame.init()
win = False


background = pygame.image.load("Rsc/Final Background.png")
backgroundRect = background.get_rect()

clock = pygame.time.Clock()

bullets = []

screenWidth = 800 
screenHeight = 600

screenSize = screenWidth, screenHeight
screen = pygame.display.set_mode(screenSize)

bgImage = pygame.image.load("RSC/Screens/Main Screen.png").convert()
bgRect = bgImage.get_rect()

bgColor = r,g,b = 0, 0, 0


playButton = Button([screenWidth/2, screenHeight-300], 
					 "RSC/Buttons/Start Base.png", 
					 "RSC/Buttons/Start Clicked.png")

run = False

bgRect = bgImage.get_rect()

player = Player([100,100])


HUDs = []

while True:
	while not run:
		for event in pygame.event.get():
			if event.type == pygame.QUIT: sys.exit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_RETURN:
					run = True
			if event.type == pygame.MOUSEBUTTONDOWN:
				playButton.click(event.pos)
			if event.type == pygame.MOUSEBUTTONUP:
				if playButton.release(event.pos):
					run = True
		bgColor = r,g,b
		screen.fill(bgColor)
		screen.blit(bgImage, bgRect)
		screen.blit(playButton.image, playButton.rect)
		pygame.display.flip()
		clock.tick(60)
		
		
	while run:
		for event in pygame.event.get():
			if event.type == pygame.QUIT: sys.exit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_w or event.key == pygame.K_UP:
					player.go("stop left")
					player.go("stop right")
					player.go("stop down")
					player.go("up")
				if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
					player.go("stop left")
					player.go("stop down")
					player.go("stop up")
					player.go("right")
				if event.key == pygame.K_s or event.key == pygame.K_DOWN:
					player.go("stop right")
					player.go("stop up")
					player.go("stop left")
					player.go("down")
				if event.key == pygame.K_a or event.key == pygame.K_LEFT:
					player.go("stop right")
					player.go("stop up")
					player.go("stop down")
					player.go("left")
			if event.type == pygame.KEYUP:
				if event.key == pygame.K_w or event.key == pygame.K_UP:
					player.go("stop up")
				if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
					player.go("stop right")
				if event.key == pygame.K_s or event.key == pygame.K_DOWN:
					player.go("stop down")
				if event.key == pygame.K_a or event.key == pygame.K_LEFT:
					player.go("stop left")
		
		
		player.update(screenWidth, screenHeight)
		
		
		screen.blit(background, backgroundRect)
		screen.blit(player.image, player.rect)
		
		pygame.display.flip()
		clock.tick(60)
		
		
		
